package pers.atomic.yang.operation;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class Number {
    private AtomicInteger ai = new AtomicInteger(0);
    private CountDownLatch latch = new CountDownLatch(10);
    private int i = 0;

    public void setAi(Integer n){
        this.ai.addAndGet(n);
    }

    public AtomicInteger getAi(){
        return this.ai;
    }

    public int getI(){
        return this.i;
    }

    public void threadOperation() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            new Thread(()-> {
//                this.setAi(1);
                this.i ++;
                this.latch.countDown();
            }).start();
        }
        this.latch.await();
    }
}
